<template>
  <div>
    <!-- 结果表格 -->
    <el-card>
      <el-table :data="dataList" stripe style="width: 100%">
        <el-table-column label="#" width="80">
          <template slot-scope="scope">
            <!-- (pageNo - 1) * pageSize + index + 1 -->
            {{
              (searchModel.pageNo - 1) * searchModel.pageSize + scope.$index + 1
            }}
          </template>
        </el-table-column>
        <el-table-column prop="id" label="合同ID" width="180" align="center">
        </el-table-column>
        <el-table-column prop="title" label="标题" width="180" align="center">
        </el-table-column>
        <el-table-column prop="boothId" label="关联摊位" width="180" align="center">
        </el-table-column>
        <el-table-column prop="startDate" label="合同开始日期" width="180" align="center">
        </el-table-column>
        <el-table-column prop="endDate" label="合同结束日期" width="180" align="center">
        </el-table-column>
        <el-table-column prop="rentalTerm" label="租赁期限（单位/月）" width="180" align="center">
        </el-table-column>
        <el-table-column prop="aname" label="摊主姓名" width="180" align="center">
        </el-table-column>
        <el-table-column prop="aphone" label="摊主电话" width="180" align="center">
        </el-table-column>
        <el-table-column prop="bname" label="租赁人姓名" width="180" align="center">
        </el-table-column>
        <el-table-column prop="bphone" label="租赁人电话" width="180" align="center">
        </el-table-column>
        <el-table-column prop="aSignDate" label="甲方签字日期" width="180" align="center">
        </el-table-column>
        <el-table-column prop="bSignDate" label="乙方签字日期" width="180" align="center">
        </el-table-column>
      </el-table>
    </el-card>

    <!-- 分页 -->
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="searchModel.pageNo"
      :page-sizes="[5, 10, 15, 20]"
      :page-size="searchModel.pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
    >
    </el-pagination>

  </div>
</template>

<script>
import contractApi from "@/api/contractManage";
export default {
  data() {
    return {
      editorOption:{},
      imageUrl: '',
      uploadUrl: 'http://localhost:8080/common/upload',
      downloadImageUrl: 'http://localhost:8080/common/download?name=',
      roleList: [],
      formLabelWidth: "130px",
      form: {},
      dialogFormVisible: false,
      title: "",
      total: 0,
      searchModel: {
        pageNo: 1,
        pageSize: 10,
      },
      dataList: [],
      rules: {
        content: [
          { required: true, message: "请输入公告内容", trigger: "blur" },
        ],
      },
    };
  },
  methods: {
    handleSizeChange(pageSize) {
      this.searchModel.pageSize = pageSize;
      this.getList();
    },
    handleCurrentChange(pageNo) {
      this.searchModel.pageNo = pageNo;
      this.getList();
    },
    beforeImageUpload(file) {
      const isJPG = file.type === 'image/jpeg' || file.type === 'image/png'
      const isLt2M = file.size / 1024 / 1024 < 2

      if (!isJPG) {
        this.$message.error('上传图片只能是 JPG 格式或者是PNG!')
      }

      if (!isLt2M) {
        this.$message.error('上传图片大小不能超过 2MB!')
      }
      return isJPG && isLt2M
    },
    handleImageSuccess(response, file) {
      this.imageUrl =
        'http://localhost:8080/common/download?name=' + response.data
      this.form.coverImage = response.data
      console.log('上传的封面:',this.form.coverImage)
    },
    getList() {
      contractApi.getList(this.searchModel).then((response) => {
        this.dataList = response.data.rows;
        this.total = response.data.total;
      });
    },
  },
  created() {
    this.getList();
  },
};
</script>

<style>
#search .el-input {
  width: 200px;
  margin-right: 10px;
}
.el-dialog .el-input {
  width: 35%;
}
</style>
